home *** CD-ROM | disk | FTP | other *** search
- #include "other MSG window.h"
- #include "environment.h"
- #include "menus.h"
- #include "util.h"
- #include "file utilities.h"
- #include "main.h"
- #include "text twiddling.h"
- #include "graphics.h"
- #include "window layer.h"
- #include "program globals.h"
- #include <Folders.h>
-
- enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
- enum { key_PageUp=0x0b, key_PageDown };
- enum { key_Home=0x01 };
- enum { key_End=0x04 };
-
- #define kGrowBoxSize 15
- #define PROGRAMS_LIST_NAME "\pMSG programs list"
- #define kListResourceID 151
- #define LIST_CREATOR 'ttxt'
- #define LIST_TYPE 'ttro'
-
- static Boolean GetListFromDisk(void);
- static Boolean SetupNewListFile(short fileID);
- static Boolean GetListFromResource(void);
- static unsigned long GetModificationDate(FSSpec *theFS);
- static void PutProductListIntoTE(WindowPtr theWindow);
-
- static short gOldForegroundTime; /* stored foreground wait time */
- static Boolean gIsActive=FALSE;
- static Handle gTheList=0L;
- static Boolean gSetupDone=FALSE;
-
- void SetupTheOtherMSGWindow(WindowPtr theWindow)
- {
- unsigned char *titleStr="\pOther MSG products";
- Point topLeft;
-
- SetWindowHeight(theWindow,
- qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
- SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
- SetWindowType(theWindow, zoomDocProc);
- topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
- topLeft.h=qd.screenBits.bounds.left+10;
- SetWindowTopLeft(theWindow, topLeft);
- SetWindowHasCloseBox(theWindow, TRUE);
- SetWindowMaxDepth(theWindow, 1);
- SetWindowDepth(theWindow, 1);
- SetWindowAutoCenter(theWindow, FALSE);
- SetWindowTitle(theWindow, titleStr);
- SetWindowIsFloat(theWindow, FALSE);
-
- if (gSetupDone)
- return;
-
- if (!GetListFromDisk())
- GetListFromResource();
- }
-
- void OpenTheOtherMSGWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
- FontInfo theFontInfo;
- Rect vScrollBarRect, hScrollBarRect;
- Rect destRect, viewRect;
-
- hTE=GetWindowTE(theWindow);
- if (hTE==0L)
- {
- SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
- GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
- SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
- GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
- SetWindowVScrollBar(theWindow,
- NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
- SetWindowHScrollBar(theWindow,
- NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
-
- GetTERect(theWindow, &destRect, TRUE);
- viewRect=destRect;
- hTE=TENew(&destRect, &viewRect);
- SetWindowTE(theWindow, hTE);
- TextFont((**hTE).txFont=36);
- TextSize((**hTE).txSize=12);
- TextFace((**hTE).txFace=0);
- GetFontInfo(&theFontInfo);
- (**hTE).fontAscent=theFontInfo.ascent;
- (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
- AdjustViewRect(hTE);
- TEAutoView(TRUE, hTE);
- TESetClickLoop((ProcPtr)MyClikLoop, hTE);
- PutProductListIntoTE(theWindow);
- }
-
- gIsActive=TRUE;
- AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
- AdjustMenus();
- }
-
- void KeyPressedInOtherMSGWindow(WindowPtr theWindow, unsigned char theChar)
- {
- TEHandle hTE;
- ControlHandle vScrollBar;
-
- if (gInProgress)
- return;
-
- hTE=GetWindowTE(theWindow);
- vScrollBar=GetWindowVScrollBar(theWindow);
-
- switch (theChar)
- {
- case key_PageUp:
- ScrollActionProc(vScrollBar, inPageUp);
- break;
- case key_PageDown:
- ScrollActionProc(vScrollBar, inPageDown);
- break;
- case key_Home:
- TEPinScroll(0, TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- case key_End:
- TEPinScroll(0, -TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- default:
- break;
- }
-
- AdjustVScrollBar(vScrollBar, hTE);
- }
-
- void MouseClickedInOtherMSGWindow(WindowPtr theWindow, Point thePoint)
- {
- short partCode;
- ControlHandle theControl;
- short scrollDistance;
- short oldSetting;
- ControlActionUPP scrollActionUPP=NewControlActionProc(ScrollActionProc);
- TEHandle hTE;
-
- if (gInProgress)
- return;
-
- partCode=FindControl(thePoint, theWindow, &theControl);
- if (theControl==GetWindowVScrollBar(theWindow))
- {
- switch (partCode)
- {
- case inThumb:
- oldSetting=GetControlValue(theControl);
- partCode=TrackControl(theControl, thePoint, 0L);
- if (partCode==inThumb)
- {
- scrollDistance=oldSetting-GetControlValue(theControl);
- if (scrollDistance!=0)
- {
- hTE=GetWindowTE(theWindow);
- TEPinScroll(0, scrollDistance*(**hTE).lineHeight, hTE);
- }
- }
- break;
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- partCode=TrackControl(theControl, thePoint, scrollActionUPP);
- break;
- }
- }
- }
-
- void DisposeTheOtherMSGWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
-
- hTE=GetWindowTE(theWindow);
- if (hTE!=0L)
- {
- TEDispose(hTE);
- SetWindowTE(theWindow, 0L);
- }
- }
-
- void ActivateTheOtherMSGWindow(WindowPtr theWindow)
- {
- gOldForegroundTime=gForegroundWaitTime;
- gForegroundWaitTime=0;
- TEActivate(GetWindowTE(theWindow));
- gIsActive=TRUE;
- HiliteControl(GetWindowVScrollBar(theWindow), 0);
- HiliteControl(GetWindowHScrollBar(theWindow), 0);
- DrawGrowIcon(theWindow);
- }
-
- void DeactivateTheOtherMSGWindow(WindowPtr theWindow)
- {
- Rect tempRect;
-
- gForegroundWaitTime=gOldForegroundTime;
- TEDeactivate(GetWindowTE(theWindow));
- gIsActive=FALSE;
- gCustomCursor=FALSE;
- HiliteControl(GetWindowVScrollBar(theWindow), 255);
- HiliteControl(GetWindowHScrollBar(theWindow), 255);
- tempRect.bottom=theWindow->portRect.bottom;
- tempRect.right=theWindow->portRect.right;
- tempRect.left=tempRect.right-kGrowBoxSize+1;
- tempRect.top=tempRect.bottom-kGrowBoxSize+1;
- EraseRect(&tempRect);
- }
-
- void CopybitsTheOtherMSGWindow(WindowPtr theWindow, WindowPtr offscreenWindowPtr)
- {
- Rect tempRect;
-
- if (gIsActive)
- {
- DrawGrowIcon(theWindow);
- }
- else
- {
- tempRect.bottom=theWindow->portRect.bottom;
- tempRect.right=theWindow->portRect.right;
- tempRect.left=tempRect.right-kGrowBoxSize+1;
- tempRect.top=tempRect.bottom-kGrowBoxSize+1;
- EraseRect(&tempRect);
- }
-
- UpdateControls(theWindow, theWindow->visRgn);
-
- tempRect=theWindow->portRect;
- tempRect.bottom-=kGrowBoxSize;
- tempRect.right-=kGrowBoxSize;
- CopyBits( &(offscreenWindowPtr->portBits),
- &(theWindow->portBits),
- &tempRect, &tempRect, 0, 0L);
- }
-
- void ResizeControlsInOtherMSGWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
- ControlHandle vScrollBar, hScrollBar;
-
- hTE=GetWindowTE(theWindow);
- vScrollBar=GetWindowVScrollBar(theWindow);
- hScrollBar=GetWindowHScrollBar(theWindow);
- AdjustScrollSizes(theWindow, hTE, vScrollBar, hScrollBar);
- AdjustViewRect(hTE);
- TECalText(hTE);
- AdjustForEndScroll(vScrollBar, hTE);
- AdjustVScrollBar(vScrollBar, hTE);
- }
-
- void GetGrowSizeOtherMSGWindow(WindowPtr theWindow, Rect *sizeRect)
- {
- SetRect(sizeRect, 200, 48+kGrowBoxSize+1, 32766, 32767);
- }
-
- /* ---------------------------------------------------- */
- /* the rest of these are internal to other MSG window.h */
-
- static void PutProductListIntoTE(WindowPtr theWindow)
- {
- long listEOF;
-
- if (gTheList==0L)
- return;
-
- listEOF=GetHandleSize(gTheList);
- HLock(gTheList);
- SetTheText(theWindow, *gTheList, listEOF);
- HUnlock(gTheList);
- TESetSelect(0, 0, GetWindowTE(theWindow));
- }
-
- static Boolean GetListFromDisk(void)
- {
- Boolean isNewFile;
- unsigned char *name=PROGRAMS_LIST_NAME;
- OSErr isHuman;
- short vRefNum;
- long dirID;
- FSSpec listFileFS, progFS;
- short listFile;
- long listEOF;
- unsigned long diskListModDate, ourListModDate;
-
- isNewFile=FALSE;
- /* find vRefNum and dirID of preferences folder, creating it if necessary */
- isHuman=FindFolder(kOnSystemDisk, 'pref', kCreateFolder, &vRefNum, &dirID);
-
- if (isHuman!=noErr) /* screwed up already?!? */
- return FALSE;
-
- isHuman=FSMakeFSSpec(vRefNum, dirID, name, &listFileFS); /* make FSSpec out of it */
- if (isHuman!=noErr)
- {
- if (isHuman==fnfErr) /* FSSpec is valid, but list file does not exist */
- {
- isHuman=FSpCreate(&listFileFS, LIST_CREATOR, LIST_TYPE, 0); /* so create it */
- if (isHuman!=noErr) /* or not */
- return FALSE;
- isNewFile=TRUE; /* signal that list file is new */
- }
- else return FALSE;
- }
- isHuman=FSpOpenDF(&listFileFS, fsRdWrPerm, &listFile); /* open list file */
- if (isHuman!=noErr)
- return FALSE;
-
- diskListModDate=GetModificationDate(&listFileFS);
- GetApplicationFSSpec(&progFS);
- ourListModDate=GetModificationDate(&progFS);
- if (diskListModDate<ourListModDate)
- isNewFile=TRUE;
-
- if (isNewFile)
- {
- if (!SetupNewListFile(listFile))
- {
- FSClose(listFile);
- FSpDelete(&listFileFS);
- return FALSE;
- }
- SetModificationDate(&listFileFS, ourListModDate);
- }
- else
- {
- GetEOF(listFile, &listEOF);
- gTheList=NewHandle(listEOF);
- if (gTheList==0L)
- {
- FSClose(listFile);
- FSpDelete(&listFileFS);
- return FALSE;
- }
- HLock(gTheList);
- SetFPos(listFile, 1, 0L);
- if (FSRead(listFile, &listEOF, *gTheList)!=noErr)
- {
- FSClose(listFile);
- FSpDelete(&listFileFS);
- DisposeHandle(gTheList);
- gTheList=0L;
- return FALSE;
- }
- HUnlock(gTheList);
- }
-
- FSClose(listFile);
- // FlushVol(dirID, vRefNum);
-
- return TRUE;
- }
-
- static Boolean SetupNewListFile(short fileID)
- {
- long listEOF;
-
- if (!GetListFromResource())
- return FALSE;
-
- listEOF=GetHandleSize(gTheList);
- if (SetEOF(fileID, listEOF)!=noErr)
- return FALSE;
-
- SetFPos(fileID, 1, 0L);
- HLock(gTheList);
- if (FSWrite(fileID, &listEOF, *gTheList)!=noErr)
- return FALSE;
- HUnlock(gTheList);
-
- return TRUE;
- }
-
- static Boolean GetListFromResource(void)
- {
- gTheList=(Handle)Get1Resource('TEXT', kListResourceID);
- if (gTheList==0L)
- return FALSE;
- if (*gTheList==0L)
- LoadResource(gTheList);
- if (*gTheList==0L)
- {
- DisposeHandle(gTheList);
- gTheList=0L;
- return FALSE;
- }
-
- DetachResource(gTheList);
-
- return TRUE;
- }
-